package com.tanhua.server.controller;

import com.tanhua.common.exception.BusinessException;
import com.tanhua.common.vo.ErrorResult;
import com.tanhua.server.service.MessagesService;
import com.tanhua.server.vo.MsgVo;
import com.tanhua.server.vo.PageMessagesVo;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;




@RestController
@RequestMapping("manage")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    /**
     * 消息通过
     * @return
     */
    @PostMapping("/messages/pass")
    public ResponseEntity<String> messagesPass(@RequestBody String[] ids) {
        //调用service
        String message = messagesService.messagesPass(ids);
        return ResponseEntity.ok(message);
    }

    /**
     * 消息置顶
     * @param id
     * @return
     */
    @PostMapping("/messages/{id}/top")
    public ResponseEntity<String> messagesTop(@PathVariable("id")ObjectId id) {
        //调用service
        String message = messagesService.messagesTop(id);
        return ResponseEntity.ok(message);
    }

    /**
     * 消息取消置顶
     * @param id
     * @return
     */
    @PostMapping("/messages/{id}/untop")
    public ResponseEntity<String> messagesUntop(@PathVariable("id")ObjectId id) {
        //调用service
        String message = messagesService.messagesUntop(id);
        return ResponseEntity.ok(message);
    }

    /**
     * 消息拒绝
     * @return
     */
    @PostMapping("/messages/reject")
    public ResponseEntity messagesReject(@RequestBody String[] ids) {
        //调用service
        String message = messagesService.messagesReject(ids);
        return ResponseEntity.ok(message);
    }

    /**
     * 消息撤销
     * @return
     */
    @PostMapping("/messages/revocation")
    public ResponseEntity revocation(@RequestBody String[] ids) {
        //调用service
        String message = messagesService.revocation(ids);
        return ResponseEntity.ok(message);
    }

    /**
     * 消息翻页
     * @param page
     * @param pagesize
     * @param sortProp
     * @param sortOrder
     * @param uid
     * @param state
     * @return
     */
    @GetMapping("/messages")
    public ResponseEntity<PageMessagesVo> pageMessages(Integer page,Integer pagesize,
                                                       String sortProp,String sortOrder,String id,
                                                       Long sd,Long ed,
                                                       Integer uid ,String state) {
        //调用service
        PageMessagesVo pageMessagesVo = messagesService.pageMessages(page,pagesize,sortProp,sortOrder,
                id,sd,ed,uid,state);
        //返回pageMessagesVo
        return ResponseEntity.ok(pageMessagesVo);
    }

    /**
     * 消息详情
     * @param id
     * @return
     */
    @GetMapping("/messages/{id}")
    public ResponseEntity<MsgVo> queryMessages(
            @PathVariable("id")String id) {
        //调用service
        MsgVo msgVo = messagesService.queryMessages(id);
        return ResponseEntity.ok(msgVo);
    }
}
